﻿using System;
using System.ComponentModel;
using System.Windows.Forms;

namespace BarberShop
{
    public partial class AddServiceForm : Form
    {
        public AddServiceForm()
        {
            InitializeComponent();
        }

        public String ServiseName { get; set; }
        public bool Billable { get; set; }

        private void AddButtonClick(object sender, EventArgs e)
        {
            AddService();
        }

        private void AddService()
        {
            if (ValidateServiceName())
            {
                ServiseName = serviceNameTextBox.Text;
                Billable = billableCheckBox.Checked;

                DialogResult = DialogResult.OK;
                Close();
            }
        }

        private void ServiceNameTextBoxValidating(object sender, CancelEventArgs e)
        {
            ValidateServiceName();
        }

        private bool ValidateServiceName()
        {
            if (serviceNameTextBox.Text == "")
            {
                errorProvider1.SetError(serviceNameTextBox, "Назва послуги не може бути порожньою");
                return false;
            }
            return true;
        }

        private void CloseButtonLinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }

        private void FilterPreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            switch (e.KeyValue)
            {
                case 13: //Enter key
                    AddService();
                    break;
                case 27: //Esc key
                    Close();
                    break;
            }
        }
    }
}